<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');

class Peserta_model extends CI_Model {

	function __construct()
	{
		parent::__construct();
		$this->CI = get_instance();
	}
	
	function insert_peserta($data){
		$this->db->insert('PESERTA',$data);
	}
	
	//list flexy
	function get_data_peserta($id_batch){
		//Select table name
		$table_name = "PESERTA";
		
		//Build contents query
		$this->db->select('*')->from($table_name);
		$this->db->where("STATUS > 0 ");
		$this->db->where("ID_BATCH", $id_batch);
		$this->CI->flexigrid->build_query();
		
		//Get contents
		$return['records'] = $this->db->get();
		
		//Build count query
		$this->db->select('*')->from($table_name);
		$this->db->where("STATUS > 0 ");
		$this->db->where("ID_BATCH", $id_batch);
		$this->CI->flexigrid->build_query(FALSE);
		
		$return['record_count'] = $this->db->count_all_results();
	
		//Return all
		return $return;
	}
	
	
	function selectone($id){
		$this->db->select('
		*,
		DAY(TANGGAL_LAHIR) as TANGGAL,
		MONTH(TANGGAL_LAHIR) as BULAN,
		YEAR(TANGGAL_LAHIR) as TAHUN,
		DAY(TANGGAL_PEMBAYARAN) as TANGGAL_BAYAR,
		MONTH(TANGGAL_PEMBAYARAN) as BULAN_BAYAR,
		YEAR(TANGGAL_PEMBAYARAN) as TAHUN_BAYAR
		');
		$this->db->from('PESERTA');
		$this->db->where('ID_PESERTA',$id);
		$query = $this->db->get();
		return $query;
	}
	
	function update_peserta($id, $data){
		$this->db->where('ID_PESERTA',$id);
		$this->db->update('PESERTA',$data);
	}
	
	function delete($id){
	$data = array(
			'STATUS' 			=> 0
		);
		$this->db->where('ID_PESERTA',$id);
		$this->db->update('PESERTA',$data);
	}
	
	
	
	function get_user(){
		$this->db->select("*");
		$this->db->from('USERS');
		$this->db->where("STATUS > 0 ");
		$query = $this->db->get();
		return $query;
	}
	
}

?>